package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.instock.pojo.dto.FormatInstockProductDTO;
import com.xbongbong.pro.instock.pojo.dto.InstockDeleteBatchDTO;
import com.xbongbong.pro.instock.pojo.dto.InstockEditAttrUpdateDTO;
import com.xbongbong.pro.instock.pojo.dto.InstockListDTO;
import com.xbongbong.pro.instock.pojo.dto.InstockUpdateByBusinessRuleDTO;
import com.xbongbong.pro.instock.pojo.vo.InstockDeleteBatchVO;
import com.xbongbong.pro.instock.pojo.vo.InstockListVO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.saas.domain.entity.InstockProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;

public interface InstockService {
    /**
     * 盘点单保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 盘点单保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;


    /**
     * 获取入库单产品
     *
     * @param businessProductListDTO 入参
     * @param jsonObject 数据对象
     * @author chaoxiong.lei
     * @Date 14:37 2019/3/5
     * @since v1.0
     * @return 入库单VO，属性product包含了出库单关联产品，返回给前端的格式
     **/
//    BusinessProductListVO getInstockProductList(BusinessProductListDTO businessProductListDTO, JSONObject jsonObject) throws XbbException;

    /**
     * 批量删除出库单
     * @author 吴峰
     * @date 2019/2/28 15:54
     * @param instockDeleteBatchDTO
     * @return com.xbongbong.pro.instock.pojo.vo.InstockDeleteBatchVO
     * @throws XbbException 业务异常
     */
    InstockDeleteBatchVO deleteBatch(InstockDeleteBatchDTO instockDeleteBatchDTO) throws XbbException;

    /**
     * 按照查询条件查找符合条件的数据从ES中
     * @param corpid 公司ID
     * @param refId 关联单据ID
     * @param type 入库类型 1采购入库，2合同订单退货入库，3盘盈入库，4调拨入库，5其他入库，6装配入库
     * @date 2019/2/27 19:20
     * @author Jian.Wang
     * @return PaasFormDataEsListVO
     */
    PaasFormDataEsListVO getInstockListFromEs(String corpid, Long refId, Integer type) throws XbbException;

    /**
     * 将入库单产品格式化返回给前端
     *
     * @param formatInstockProductDTO 格式化入库单产品DTO
     * @Date 22:20 2019/3/4
     * @since v1.0
     * @return 一个入库单产品的JSONObject
     **/
    JSONObject getFormatProductJsonArray(FormatInstockProductDTO formatInstockProductDTO) throws XbbException;

    /**
     * 入库单产品保存
     * @param productArray 产品数组
     * @param corpid 公司id
     * @param instockId 对应入库单的id
     * @param refId
     * @param formId
     * @param isWorkflow
     * @author lcx
     * @date 2019-02-01 15:19
     */
    void saveProduct(JSONArray productArray, String corpid, Long instockId, Integer type, Long refId, Long formId, boolean isWorkflow) throws XbbException;

    /**
     * 获取入库单
     * @param instockListDTO
     * @return
     * @throws XbbException
     */
    InstockListVO findInstockList(InstockListDTO instockListDTO) throws XbbException;

    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/20 14:40
     * @param instockEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(InstockEditAttrUpdateDTO instockEditAttrUpdateDTO) throws XbbException;

    /**
     * 关联新建时格式化解释
     * @author 吴峰
     * @date 2019/4/1 21:56
     * @param handlerExplainInLinkItemDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 详情格式化解释
     * @author 吴峰
     * @date 2019/4/11 22:07
     * @param formatExplainDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void formatGetExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author lee
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * Description: 入库单 仓库一致性同步
     * @param corpid
     * @param dataId
     * @param name
     * @return void
     * @author 魏荣杰
     * @date 2019/8/5 11:30
     * @since v1.0
     */
    void dataConsistencyUpdateWarehouse(String corpid, Long dataId, String name) throws XbbException;

    /**
     * 根据业务规则，更新入库单
     * @author 吴峰
     * @date 2019/8/19 16:19
     * @param instockUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(InstockUpdateByBusinessRuleDTO instockUpdateByBusinessRuleDTO) throws XbbException;

    /**
     * 汇总入库单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;
    /**
     * Description: 入库单 采购合同编号一致性同步
     * @param corpid
     * @param dataId
     * @param serialNo
     * @return void
     * @author jyh
     * @date 2019/11/27 15.10
     * @since v1.0
     */
    void dataConsistencyUpdateSeriNo(String corpid, Long dataId, String serialNo) throws XbbException ;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, Boolean forProcess, Integer operate, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    /**
     * 解析
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(InstockProductEntity entity);

    /**
     * 自动生成入库单单据
     * @param saasFormSaveDTO
     * @throws XbbException
     */
    void generateInStockSheet(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void negativeStockCheck(String corpid, Map<String, InstockProductEntity> warehouseMap, Map<String, InstockProductEntity> disableBatchProducts) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    /**
     * 供应商名称一致性同步
     *
     * @param corpid 公司ID
     * @param supplierId  供应商ID
     * @param supplierName 供应商名称
     * @throws XbbException
     */
    void dataConsistencyUpdateSupplier(String corpid, Long supplierId, String supplierName) throws XbbException;


    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

}
